package httphandler

import (
	"fmt"
	"runtime"
	"strconv"

	"chat.com/common"
	"chat.com/server/wsserver/connection"
	"chat.com/server/wsserver/service"
	"github.com/gin-gonic/gin"
)

// 查询系统状态
func Status(c *gin.Context) {
	isDebug := c.Query("isDebug")
	fmt.Println("http_request 查询系统状态", isDebug)

	data := make(map[string]interface{})
	numGoroutine := runtime.NumGoroutine()
	numCPU := runtime.NumCPU()

	// goroutine 的数量
	data["numGoroutine"] = numGoroutine
	data["numCPU"] = numCPU
	// ClientManager 信息
	data["managerInfo"] = connection.GetManagerInfo(isDebug)

	Response(c, common.OK, "", data)
}

// 查看全部在线用户
func List(c *gin.Context) {
	appIdStr := c.Query("appId")
	appId, _ := strconv.ParseInt(appIdStr, 10, 64)

	fmt.Println("http_request 查看全部在线用户", appId)

	data := make(map[string]interface{})

	userList, userCount := service.AllUsers(appId)
	data["userList"] = userList
	data["userCount"] = userCount

	Response(c, common.OK, "OK", data)
}
